def prime(x):
    g = True
    for h in range(2, int(x ** 0.5)+1):
        if x % h == 0:
            g = False
            break
    return g

g = int(input())
if g < 1000 or g > 9999:
    print(0)
else:
    dgts = str(g)
    mx = 0
    for i in range(len(dgts)):
        for j in range(i+1, len(dgts)+1):
            num = int(dgts[i:j])
            if prime(num):
                mx = max(mx, num)
    print(mx)
